#include "TObject.h"

//#include "TObjectList.h"
#include "iostream"
using namespace std;
TObject::TObject()
{
    m_data = NULL;
    m_itemType = ItemType_Unknown;
}

TObject::TObject(int obj)
{
    m_data = (Object)(new int(obj));
    m_itemType = ItemType_Int;
}

TObject::TObject(float obj)
{
    m_data = (Object)(new float(obj));
    m_itemType = ItemType_Float;
}

TObject::TObject(string obj)
{
    m_data = (Object)(new string(obj));
    m_itemType = ItemType_String;
}

TObject::TObject(TObjectList * obj)
{
    m_data = (Object)obj;
    m_itemType = ItemType_List;
}

TObject::~TObject()
{
    if(m_data != NULL)
    {
        switch(m_itemType)
        {
        case ItemType_Int://cout<<"TObject deconstrucation ItemType_Int"<<endl;
            delete reinterpret_cast<int *>(m_data);
            break;
        case ItemType_Float://cout<<"TObject deconstrucation ItemType_Float"<<endl;
            delete reinterpret_cast<float *>(m_data);
            break;
        case ItemType_String://cout<<"TObject deconstrucation ItemType_String"<<endl;
            delete reinterpret_cast<string *>(m_data);
            break;
        case ItemType_List:///cout<<"TObject deconstrucation ItemType_List"<<endl;
            delete reinterpret_cast<TObjectList *>(m_data);
            break;
        default://cout<<"TObject deconstrucation default"<<endl;
            delete m_data;
        }
        m_data = NULL;
    }/*else
    {
        cout<<"TObject deconstrucation NOOP"<<endl;
    }*/
}

int TObject::getInt()
{
    return *((int*)m_data);
}

float TObject::getFloat(){
    return *((float*)m_data);
}

string TObject::getString()
{
    return ((string*)m_data) -> c_str();
}

TObject * TObject::getObject()
{
    return (TObject*)m_data;
}

TObjectList * TObject::getObjectList()
{
    return (TObjectList*)m_data;
}

ItemType TObject::getObjectType()
{
    return m_itemType;
}
